package com.example.provider.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA 2023.
 * Description:
 * User: 故我
 * Date: 2024-01-12
 * Time: 13:01
 */
@RestController
@RequestMapping("/user")
public class UserController {

//    @Value("${server.port}")
//    private Integer port;

    // 得到动态端口号
    @Autowired
    private ServletWebServerApplicationContext context;

    @RequestMapping("/getuserbyid")
    public String getUserById(Integer id) {
        return "provider : " + id + " | port : " + context.getWebServer().getPort();
    }
}
